//
//  Player_Loop_Mode_Btn.m
//  ICE_Player
//
//  Created by lijinxin on 11-10-19.
//  Copyright (c) 2011年 __MyCompanyName__. All rights reserved.
//

#import <QuartzCore/QuartzCore.h>
#import "Player_Loop_Mode_Btn.h"
#import "ICE_global_var.h"

@implementation Player_Loop_Mode_Btn
@synthesize state;

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
    }
    return self;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
}
*/

- (void)dealloc {
	[self destroy_SubViews];
    [super dealloc];
}

- (void)create_SubViews:(UIViewController*)controller
{
    [super create_SubViews:controller];
}

- (void)scale_to_fit_iPad
{
    /*CGRect rect = self.bounds;
     CGPoint pnt = {0};
     rect.origin.x = 100.f;
     rect.origin.y = 768.f - 100.f;
     rect.size.width = 1024.f - 100.f - 100.f;
     pnt.x = rect.origin.x + 0.5f * rect.size.width;
     pnt.y = rect.origin.y + 0.5f * rect.size.height;
     self.bounds = rect;
     self.center = pnt;*/
}

- (void) setHidden:(BOOL)enabled
{
    E_LOOP_MODE lm = gf_get_ice_cfg()->loop_mode;
    switch (lm)
    {
        case E_LM_NO_LOOP:
            self.state = E_PLM_NO_LOOP;
            break;
        case E_LM_SINGLE_LOOP:
            self.state = E_PLM_SINGLE_LOOP;
            break;
        case E_LM_LIST_LOOP:
            self.state = E_PLM_LIST_LOOP;
            break;
        case E_LM_RANDOM:
            self.state = E_PLM_RANDOM;
            break;
        default:
            break;
    }
    if (enabled)
    {
        CATransition *animation = [CATransition animation];
        animation.delegate = self;
        animation.duration = 0.15f;
        animation.timingFunction = UIViewAnimationCurveEaseInOut;
        animation.fillMode = kCAFillModeForwards;//kCAFillModeBackwards;//
        animation.type = kCATransitionFade;//@"rippleEffect";//110
        //animation.subtype = kCATransitionFromRight;//kCATransitionFromTop;
        //animation.endProgress = 1.0;
        //animation.removedOnCompletion = NO;
        
        //[self.layer addAnimation:animation forKey:@"animation"];
        [self.layer addAnimation:animation forKey:@"animation"];
        
    }
    else
    {
        CATransition *animation = [CATransition animation];
        animation.delegate = self;
        animation.duration = 0.15f;
        animation.timingFunction = UIViewAnimationCurveEaseInOut;
        animation.fillMode = kCAFillModeForwards;//kCAFillModeBackwards;//
        animation.type = kCATransitionFade;//@"rippleEffect";//110
        //animation.subtype = kCATransitionFromRight;//kCATransitionFromTop;
        //animation.endProgress = 1.0;
        //animation.removedOnCompletion = NO;
        
        //[self.layer addAnimation:animation forKey:@"animation"];
        [self.layer addAnimation:animation forKey:@"animation"];
    }
	super.hidden = enabled;
}

- (void)destroy_SubViews
{
}

- (void)setState:(E_PLAYER_LOOP_MODE)st
{
    /*if (state == st)
    {
        return;
    }*/
    switch (st)
    {
        case E_PLM_NO_LOOP:
            [self setImage:[UIImage imageNamed:@RESOURCE_PATH_NO_LOOP] forState:UIControlStateNormal];
            break;
        case E_PLM_LIST_LOOP:
            [self setImage:[UIImage imageNamed:@RESOURCE_PATH_LIST_LOOP] forState:UIControlStateNormal];
            break;
        case E_PLM_SINGLE_LOOP:
            [self setImage:[UIImage imageNamed:@RESOURCE_PATH_SINGLE_LOOP] forState:UIControlStateNormal];
            break;
        case E_PLM_RANDOM:
            [self setImage:[UIImage imageNamed:@RESOURCE_PATH_RANDOM] forState:UIControlStateNormal];
            break;
        default:
            break;
    }
    state = st;
    //[self layoutSubviews];
}

@end
